package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    void add(AddressBook addressBook);

    /**
     * 根据userId查询地址
     * @param currentId
     * @return
     */
    @Select("select * from address_book where user_id=#{currentId}")
    List<AddressBook> findByUserId(Long currentId);

    /**
     * 根据id修改默认值
     * @param isDefault
     * @param id
     */
    @Update("update address_book set is_default =#{isDefault} where id=#{id}")
    void updateByDefault(Integer isDefault,Integer id);

    /**
     * 查询默认地址
     * @param i
     * @return
     */
    @Select("select * from address_book where is_default =#{i}")
    AddressBook findDefault(int i);

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Select("select * from address_book where id = #{id}")
    AddressBook getById(Long id);
    /**
     * 根据id修改
     * @param addressBook
     */
    void update(AddressBook addressBook);
    /**
     * 根据id删除地址
     * @param id
     */
    @Delete("delete from address_book where id = #{id}")
    void deleteById(Long id);
}
